<template>
	<div v-loading="loading">
		<el-tabs v-model="activeName" @tab-click="handleTabChange">
			<el-tab-pane v-for="(item, index) in tabsList" :key="index" :label="item.label" :name="item.value"> </el-tab-pane>

			<div class="content-card">
				<component
					v-if="!loading"
					class="pd10"
					:is="whickComm[activeName]"
					@refresh="handleRefresh"
					:nowRowData="info"
					:actionBtn="false"
					:searchConfig="false"
          :soleKey="`dpFoundationPractitioners-${nowRowData.idCard}`"
				>
				</component>
			</div>
		</el-tabs>
	</div>
</template>

<script setup lang="ts">
import BaseDetail from './BaseDetail/index.vue'
import Extend from './Extend/index.vue'
import { useCommonStore } from '@/stores/common'
import { useOperate } from '@/views/datacenter/hooks/useConfig'
import information from './information/index.vue'
import apiMod from '@/apiMod/index'
import { getAreaObj } from '@/utils/util'


const { onDelete, onMessageChange } = useOperate(5)
const { setTempParams } = useCommonStore()

const whickComm = {
	BaseDetail,
	Extend,
    information
}
type Props = {
	nowRowData?: any
	showBtn?: boolean
}
const props = withDefaults(defineProps<Props>(), {
	showBtn: false,
})


const emit = defineEmits(['refresh', 'rechange'])
const loading = ref(false)
const activeLabelTitle = ref('基础信息')

const tabsList: any = [
	{ label: '基础信息', value: 'BaseDetail' },
	{ label: '扩展信息', value: 'Extend' },
	{ label: '资料信息', value: 'information' },
]
const activeName = ref('BaseDetail')


// 通过身份证获取从业人员信息
let info = ref({idCard:props.nowRowData.idCard})
const getInfo = async(idCard) =>{
    loading.value = true
    let res =await apiMod.view_dpFoundationPractitioners_page({ idCard:idCard,code:2007 })
    if(res.code==0){
        const tableData = res.data.records.map((item) => {
			const unitAddress: any = getAreaObj(item, 'unit', 'set')
			return {
				...(item.dpFoundationPractitionersExtendPO || {}),
				...item,
				unitAddress: unitAddress.names,
				tableAreaName: [item.unitAreaName, item.unitStreetName, item.unitCommunityName].filter(Boolean).join(''),
			}
		})
		if(tableData.length>0){
			info.value = tableData[0]
		}
        loading.value = false
    }else{
        loading.value = false
    }
}
provide('nowRowData',info.value)
getInfo(props.nowRowData.idCard)



const handleTabChange = (tab) => {
	activeLabelTitle.value = tab.props.label
}

const handleRefresh = () => {
	emit('refresh')
}
</script>

<style scoped></style>
